﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using PDAMain.DAL;

using PDAMain.Entity;

namespace PDAMain.Forms.CustomerWork
{
    public partial class CustomerDetail : Form
    {
        public string customerID;
        public CustomerDetail()
        {
            InitializeComponent();
        }

        private void RepairOrder_Click(object sender, EventArgs e)
        {
            //轉維修工單
            CustomerToRepair repair = new CustomerToRepair();
            repair.customerID = customerID;
            repair.Show();
            this.Close();
        }

        private void menuItem3_Click(object sender, EventArgs e)
        {
            //轉單
            CustomerTransfer transfer = new CustomerTransfer();
            transfer.customerID = customerID;
            transfer.Show();
            this.Close();
        }

        private void CustomerDetail_Load(object sender, EventArgs e)
        {
            BindData();
        }

        //加载数据
        private void BindData()
        {
            //獲取數據
            DataTable dt = new DataTable();
            dt = DataHelper.CustomerWorkDao.getDetail(customerID).Tables[0];
            if (dt.Rows.Count == 0)
                return;

            lblActiveID.Text = dt.Rows[0]["CWOrder_No"].ToString();
            lblStatus.Text = DataHelper.CustomerWorkDao.getShow(dt.Rows[0]["STATUS"].ToString());
            lblAddress.Text = dt.Rows[0]["Address"].ToString();
            lblContactName.Text = dt.Rows[0]["User_Name"].ToString();
            llbContactPhone.Text = dt.Rows[0]["User_Phone"].ToString();
            lblPriority.Text = dt.Rows[0]["Event_Level"].ToString();
            lblDescription.Text = dt.Rows[0]["DESCRIPTION"].ToString();
            lblDutyPerson.Text = Identity.dutyPerson;
            lblRemark.Text = dt.Rows[0]["Comment"].ToString();
           
        }

        private void menuItem6_Click(object sender, EventArgs e)
        {
            //現場工單
            CustomerToFastRepair fastRepair = new CustomerToFastRepair();
            fastRepair.customerID = customerID;
            fastRepair.Show();
            this.Close();
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            //返回
            backToList();
        }

        private void menuItem7_Click(object sender, EventArgs e)
        {
            //处理完成
            if (MessageBox.Show("你确定要执行此操作吗？", "提示框", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Cancel)
                return;
            if (DataHelper.CustomerWorkDao.deal(customerID, "9", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), lblRemark.Text))
            {
                MessageBox.Show("成功同步数据至远程数据库");
            }
            else
            {
                if (DataHelper.CustomerWorkDao.insertLacolTable(customerID, "9", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), lblRemark.Text))
                {
                    MessageBox.Show("同步数据失败，保存至本地数据库");
                }
                else
                {
                    MessageBox.Show("保存失败");
                }
            }
            backToList();
        }

        private void llbContactPhone_Click(object sender, EventArgs e)
        {
            //调用打电话
            PhoneDailing.MakeCall(llbContactPhone.Text.ToString());
        }

        private void backToList()
        {
            CustomerList list = new CustomerList();
            list.Show();
            this.Close();
        }

        

       
        

       
    }
}